package com.ymttest.database.sqlwapper.sqdistributor;

import java.util.HashMap;
import java.util.List;

import com.ymt.database.SqlManager;
import com.ymttest.database.model.sqdistributor.DistributorConsumerWechatRelation;

public class DistributorConsumerWechatRelationWrapper {
	
	SqlManager manager;

	public DistributorConsumerWechatRelationWrapper() {
		manager = new SqlManager("sqdistributor");
	}

	@SuppressWarnings("unchecked")
	public DistributorConsumerWechatRelation selectByPrimaryKey(Long id) {

		DistributorConsumerWechatRelation distributorConsumerWechatRelation = null;
		List<DistributorConsumerWechatRelation> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.sqdistributor.DistributorConsumerWechatRelationMapper.selectByPrimaryKey",
						id);
		manager.commit();

		if (result.size() > 0) {
			distributorConsumerWechatRelation = result.get(0);
		}

		return distributorConsumerWechatRelation;
	}
	
	@SuppressWarnings("unchecked")
	public DistributorConsumerWechatRelation selectByMerchantIdAndUserId(
			Long merchantId, Long userId) {

		DistributorConsumerWechatRelation distributorConsumerWechatRelation = null;

		HashMap<String, Long> map = new HashMap<>();

		map.put("merchantId", merchantId);
		map.put("userId", userId);

		List<DistributorConsumerWechatRelation> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.sqdistributor.DistributorConsumerWechatRelationMapper.selectByMerchantIdAndUserId",
						map);
		manager.commit();

		if (result.size() > 0) {
			distributorConsumerWechatRelation = result.get(0);
		}

		return distributorConsumerWechatRelation;
	}
	
	@SuppressWarnings("unchecked")
	public DistributorConsumerWechatRelation selectByMerchantIdAndOpenId(
			Long merchantId, String openId) {

		DistributorConsumerWechatRelation distributorConsumerWechatRelation = null;

		HashMap<String, Object> map = new HashMap<>();

		map.put("merchant_id", merchantId);
		map.put("open_id", openId);

		List<DistributorConsumerWechatRelation> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.sqdistributor.DistributorConsumerWechatRelationMapper.selectByMerchantIdAndOpenId",
						map);
		manager.commit();

		if (result.size() > 0) {
			distributorConsumerWechatRelation = result.get(0);
		}

		return distributorConsumerWechatRelation;
	}
	
	public static void main(String[] args) {
		
		DistributorConsumerWechatRelationWrapper test = new DistributorConsumerWechatRelationWrapper();
		
		System.out.println(test.selectByMerchantIdAndOpenId(500861041L, "9hy4lHs3zX"));
	}
}
